// 获取数据资源信息并动态渲染
$(function () {
    //顶部搜索
    $(".searchKeyword").click(function () {
        $(".searchHeaderBox").removeClass("disabledNone")
    })
    $("#closeSearchHeaderBox").click(function () {
        $(".searchHeaderBox").addClass("disabledNone")
    })
})
$(function () {
    let url = window.location.search
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg); //匹配目标参数
        if (r != null) return unescape(r[2]);
        return null; //返回参数值
    }
    let dataSourceList = []
    $.ajax({
       timeout:30000,
        type: 'GET',
        url: window.Http + "/customer/datasourceContent/info/" + getUrlParam('sourceId'),
        headers: {
            'Authorization': "Bearer " + sessionStorage.getItem('Token')
        },
        success: function (res) {
            if (res.code == 200) {
                let num = (Math.ceil(res.data.score))*31;//模拟评分
                dataSourceList = res.data;
                let status = {
                    '-1': '保存',
                    '0': '正常',
                    '1': '故障',
                    '2': '未审核',
                    '3': '未测试',
                }
                console.log('res.data', res.data)
                $("#detail").html(res.data.detail);
                $("#example").html(res.data.example||'无');
                $("#contentNickName span").html(res.data.contentNickName);
                $("#departInfo span").html(res.data.departInfo);
                $("#contentName span").html(res.data.contentName);
                $("#createTime span").html(res.data.createTime.slice(0, 10));
                $("#createBy span").html(res.data.createBy);
                $("#firstType span").html(res.data.firstType);
                $("#status span").html(status[res.data.status]);
                $("#sharedType span").html(res.data.controlRuleId===-1?'无条件共享':'有条件共享');

                $("#viewNumber span").html(res.data.viewNumber);
                $("#score span ").html(`<div class="atar_Show">
												  <p tip="5" style="width:${num}px"></p>
												</div>`)
            }else{
				layer.alert(res.msg, {
				    icon: 5,
				    title: ""
				});
			}
        }
    })
    // 点击查看关联产品，（目前传递的参数不对）
    $('.RelatedProducts').click(function () {
        $('.RelatedProductMenu').empty()
        $.ajax({
       timeout:30000,
            url: window.Http + "/customer/product/list",
            type: 'GET',
            headers: {
                'Authorization': "Bearer " + sessionStorage.getItem('Token')
            },
            data: { contentId: getUrlParam('sourceId'),status:0 },
            success: function (res) {
                if (res.code === 200) {
                    let html = '';
                    if (res.rows.length>0) {
                        res.rows.forEach(val => {
                            let num = (Math.ceil(val.score))*31;//模拟评分
                            html +=
                                `
									<div class="card shadow-sm border-0" data-ID="${val.id}">
										<div class="card-header border-0" >
											<h3 class="my-0 font-weight-normal">${val.productName}</h3>
										</div>
										<div class="card-body">
											<ul class="list-unstyled mt-2 mb-2">
												<li>
													<div style="width:176px;height:99px"><img src="${val.iconUrl ? val.iconUrl:'./assets/img/demo/iconURL1.jpg'}" /></div>
												</li>
												<li>
													<span style="border: 1px solid #0ac382;border-radius: 2px;font-size: 12px;color: #0ac382;line-height: 18px;margin-right: 6px;padding: 0 6px;">${val.brief}</span>
												</li>
												<li>
													<span style="color: #8890a7;font-size:12px;margin-left: -7px;">
												<div class="atar_Show">
												  <p tip="5" style="width:${num}px"></p>
												</div>
												<span></span>
											</span>
												</li>
												<li style="font-weight:400;font-size:12px;line-height:25px;color: #8890a7;">
													<span>访问次数：${val.visitCount}</span>
													<span style="float:right">申购次数：${val.buyCount}</span>
												</li>
												<li style="color: #8890a7;font-size: 14px;overflow: hidden;height: 42px;margin-bottom: 5px;">描述：${val.definition}</li>
											</ul>
										</div>
									</div>
									`

                        })
                        $('.RelatedProductMenu').append(html)
                    } else {
                        layer.alert('没有关联产品', {
                            icon: 5,
                            title: ""
                        });
                    }
                }
            }
        })
    })

    // 自定义数据产品
    $(".productRegistration").click(function () {
        window.dataProductId = null;
        layer.open({
            type: 2,
            title: "产品注册",
            area: ['1200px', '800px'],
            content: './popupPage/productRegistryPop.html'
        });
    })
    // 请卖家定制产品
    $(".applyMadeDIY").click(function () {
        // sessionStorage.setItem("ISDIY", "1");
        let contentId= getUrlParam('sourceId')
        layer.open({
            type: 2,
            title: "申请产品定制",
            area: ['800px', '600px'],
            content: `./popupPage/applyMadePop.html?contentId=${contentId}`,//这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no'],
            // end: function () {
            //     let parame = {
            //         currPage,
            //         pageSize,
            //     }
            //     requestData(parame)
            // }
        });

    })
})